home *** CD-ROM | disk | FTP | other *** search
- unit Launch1U;
-
- {$ifdef Win32}
- 'This one is for Windows 3.1x & Delphi 1'
- {$endif}
-
- interface
-
- uses
- WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls;
-
- type
- TForm1 = class(TForm)
- dlgOpen: TOpenDialog;
- btnRefresh: TButton;
- lstWindows: TListBox;
- Timer1: TTimer;
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure btnRefreshClick(Sender: TObject);
- public
- Wnd: HWnd;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- ToolHelp;
-
- {$R *.DFM}
-
- procedure DescribeWnd(Wnd: HWnd; List: TStrings);
- const
- FlagStr: array[Boolean] of String = ('not ', '');
- var
- CString: array[0..255] of Char;
- Rect: TRect;
- begin
- with List do
- begin
- BeginUpdate;
- try
- { Check the window is valid }
- if not IsWindow(Wnd) then
- begin
- Add('Window is not valid');
- Abort
- end;
- Add(Format('Window handle = $%x', [Wnd]));
- { Get window caption }
- GetWindowText(Wnd, CString, SizeOf(CString));
- Add(Format('Window caption is "%s"', [CString]));
- { get window dimensions }
- GetWindowRect(Wnd, Rect);
- with Rect do
- Add(Format('Window co-ordinates are (%d,%d) - (%d,%d)',
- [Left, Top, Right, Bottom]));
- Add(Format('Window is from app with instance handle of $%x',
- [GetWindowWord(Wnd, gww_HInstance)]));
- { Get thread id & process id of owning app }
- Add(Format('Window is from app with task handle of $%x',
- [GetWindowTask(Wnd)]));
- Add(Format('Window has ID of $%x', [GetWindowWord(Wnd, gww_ID)]));
- Add(Format('The window is %svisible', [FlagStr[IsWindowVisible(Wnd)]]));
- Add(Format('The window is %senabled', [FlagStr[IsWindowEnabled(Wnd)]]));
- Application.Icon.Handle := GetClassWord(Wnd, gcw_HIcon);
- Add('The window''s icon has been set as this application''s icon');
- Add('The window''s caption bar should be flashing')
- finally
- EndUpdate
- end
- end
- end;
-
- function EnumFunc(Wnd: HWnd; PWnd: PHandle): Bool; far;
- begin
- Result := False;
- PWnd^ := Wnd
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- var
- CString: array[0..255] of Char;
- Inst, Task: THandle;
- TE: TTaskEntry;
- begin
- { Set open dialog to look in Windows directory }
- GetWindowsDirectory(CString, SizeOf(CString));
- dlgOpen.InitialDir := StrPas(CString);
- if dlgOpen.Execute then
- begin
- { Launch chosen app }
- StrPCopy(CString, dlgOpen.FileName);
- Inst := WinExec(CString, sw_ShowNormal);
- { Turn instance handle into task handle }
- FillChar(TE, SizeOf(TE), 0);
- TE.dwSize := SizeOf(TE);
- if TaskFirst(@TE) then
- repeat
- if TE.hInst = Inst then
- Task := TE.hTask
- else if TE.hModule = Inst then
- Task := TE.hTask
- until (TE.hInst = Inst) or (TE.hModule = Inst) or not TaskNext(@TE);
- { Loop thru all task's windows }
- EnumTaskWindows(Task, @EnumFunc, Longint(@Wnd));
- { Fill listbox with info on the main window }
- DescribeWnd(Wnd, lstWindows.Items);
- end
- end;
-
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- { Flash the window's caption bar }
- if IsWindow(Wnd) then
- FlashWindow(Wnd, True)
- end;
-
- procedure TForm1.btnRefreshClick(Sender: TObject);
- begin
- lstWindows.Clear;
- DescribeWnd(Wnd, lstWindows.Items);
- end;
-
- end.
-